import * as echarts from 'echarts'

// 注册地图
import chinaMapData from '../data/china.json'
echarts.registerMap("chinaMap", chinaMapData)

export function useEchart(el: HTMLElement) {
  const echartInstance = echarts.init(el)
  const setOption = (options: echarts.EChartsOption) => {
    echartInstance.setOption(options)
  }

  // echarts根据宽度自适应
  window.addEventListener('resize', () => {
    echartInstance.resize()
  })

  return {
    echartInstance,
    setOption
  }
}
